export default {
    namespaced: true,
    state() {
        return {
            // 搜索关键字
            searchTitle: JSON.parse(localStorage.getItem('search_title')) || "",
            // 搜索结果
            searchData: JSON.parse(localStorage.getItem('search_data')) || "{}"
        }
    },
    mutations: {
        // 保存到本地
        saveTtleToLocalStorage(state) {
            localStorage.setItem('search_title', JSON.stringify(state.searchTitle))
        },
        // 更改搜索关键字
        updateSearchTitle(state, title) {
            state.searchTitle = title
            // 持久化
            this.commit("m_search/saveTtleToLocalStorage")
        },
        saveDataToLocalStorage(state) {
            localStorage.setItem('search_data', JSON.stringify(state.searchData))
        },
        // 更改搜索结果
        updateSearchData(state, data) {
            state.searchData = data
            // 持久化
            this.commit("m_search/saveDataToLocalStorage")
        }
    }
}